//
//  LoginTextFiledView.m
//  League
//
//  Created by 博宇 李 on 2018/1/22.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "LoginTextFiledView.h"

@implementation LoginTextFiledView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame=frame;
        
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    self.backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    self.backgroundImageView.backgroundColor = [UIColor blackColor];
    [self addSubview:self.backgroundImageView];
    
    self.LogImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width/1.2, self.height/6)];
    self.LogImageView.center = CGPointMake(self.width/2, self.LogImageView.height+self.LogImageView.height/2);
    self.LogImageView.backgroundColor = [UIColor clearColor];
    self.LogImageView.image = [UIImage imageNamed:@"LogHeadImage"];
//    self.LogImageView.layer.masksToBounds = YES;
//    self.LogImageView.layer.cornerRadius = 8;
    [self addSubview:self.LogImageView];
    
     self.userNameView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width/1.2, self.height/13)];
     self.userNameView.center = CGPointMake(self.width/2, self.LogImageView.frame.origin.y+self.LogImageView.height+self.userNameView.height*2);
    self.userNameView.backgroundColor = [UIColor whiteColor];
    self.userNameView.layer.masksToBounds = YES;
    self.userNameView.layer.cornerRadius = 8;
    [self addSubview:self.userNameView];
    
    self.userNameTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.userNameView.width*0.75, self.userNameView.height)];
    self.userNameTf.center = CGPointMake(self.userNameView.width - self.userNameTf.width/2, self.userNameView.height/2);
    self.userNameTf.tag = 1000;
    self.userNameTf.backgroundColor = [UIColor clearColor];
    self.userNameTf.placeholder = @"请输入手机号";
//    self.userNameTf.text = @"18580738007";
//    self.userNameTf.text = @"13277059651";
    self.userNameTf.font = [UIFont fontWithName:kFontName size:self.userNameTf.height/3.5];
    [self.userNameView addSubview:self.userNameTf];
    
    self.countryNumberBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.userNameView.width - self.userNameTf.width, self.userNameView.height)];
    self.countryNumberBtn.backgroundColor = [UIColor clearColor];
    self.countryNumberBtn.titleLabel.font=[UIFont fontWithName:kFontName size:self.countryNumberBtn.height/3.5];
    [self.countryNumberBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.userNameView addSubview:self.countryNumberBtn];
    
    self.userPassWordTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.width/1.2, self.height/13)];
    self.userPassWordTf.center = CGPointMake(self.userNameView.x+self.userPassWordTf.width/2, self.userNameView.frame.origin.y+self.userNameView.height+self.userPassWordTf.height);
    self.userPassWordTf.placeholder = @"请输入验证码";
//    self.userPassWordTf.text = @"123456";
    self.userPassWordTf.secureTextEntry = YES;
    self.userPassWordTf.tag = 1001;
    self.userPassWordTf.backgroundColor = [UIColor whiteColor];
    self.userPassWordTf.layer.masksToBounds = YES;
    self.userPassWordTf.layer.cornerRadius = 8;
    self.userPassWordTf.font=[UIFont fontWithName:kFontName size:self.userPassWordTf.height/3.5];
    [self addSubview:self.userPassWordTf];
    
    UIView *leftView_password = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 0)];
    leftView_password.backgroundColor = [UIColor whiteColor];
    self.userPassWordTf.leftView = leftView_password;
    self.userPassWordTf.leftViewMode = UITextFieldViewModeAlways;
    
    
    self.forgetPWBtn =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.userNameView.width /2, self.userPassWordTf.height)];
    self.forgetPWBtn.center = CGPointMake(self.userPassWordTf.x+self.userPassWordTf.width-self.forgetPWBtn.width/2, self.userPassWordTf.y+self.userPassWordTf.height+self.forgetPWBtn.height/2);
    self.forgetPWBtn.backgroundColor = [UIColor clearColor];
    self.forgetPWBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
    [self.forgetPWBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    [self.forgetPWBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.forgetPWBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//    self.forgetPWBtn.layer.masksToBounds = YES;
//    self.forgetPWBtn.layer.cornerRadius = 8;
//    self.forgetPWBtn.layer.borderWidth = 2;
//    self.forgetPWBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.forgetPWBtn.titleLabel.font=[UIFont fontWithName:kFontName size:self.forgetPWBtn.height/3.5];
    [self addSubview:self.forgetPWBtn];
    
    
    self.remberPwImage = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,self.userNameView.height/2 , self.userNameView.height/2)];
    self.remberPwImage.center = CGPointMake(self.userNameView.x+self.remberPwImage.width/2,  self.forgetPWBtn.y+ self.forgetPWBtn.height/2);
//    self.remberPwImage.backgroundColor = [UIColor redColor];
    
    [self.remberPwImage setImage:[UIImage imageNamed:@"normpw"] forState:UIControlStateNormal];
    [self.remberPwImage setImage:[UIImage imageNamed:@"isrmpw"] forState:UIControlStateSelected];
    [self addSubview:self.remberPwImage];
    
    self.remberPwbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.forgetPWBtn.width/2, self.forgetPWBtn.height)];
    self.remberPwbtn.center = CGPointMake(self.remberPwImage.x+self.remberPwImage.width+self.remberPwbtn.width/2 - 10, self.forgetPWBtn.y+self.forgetPWBtn.height/2);
//    self.remberPwbtn.backgroundColor = [UIColor blueColor];
    self.remberPwbtn.titleLabel.font =[UIFont fontWithName:kFontName size:self.remberPwImage.height/2];
    [self addSubview:self.remberPwbtn];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *firstName = [defaults objectForKey:kIsremberPw];
    if([firstName isEqualToString:kIsremberStr])
    {
        self.remberPwImage.selected = YES;
        self.userNameTf.text = [defaults objectForKey:kUserName];
        self.userPassWordTf.text = [defaults objectForKey:kUserPassWord];
    }
    else
    {
        self.remberPwImage.selected = NO;
    }
    
    
    self.changLau = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.width/1.2, self.height/12)];
    self.changLau.center = CGPointMake(self.width/2, self.height - self.changLau.height);
    //    self.changLau.backgroundColor = [UIColor redColor];
//    self.changLau.layer.masksToBounds = YES;
//    self.changLau.layer.cornerRadius = 8;
//    self.changLau.layer.borderWidth = 2;
//    self.changLau.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.changLau.titleLabel.font=[UIFont fontWithName:kFontName size:self.changLau.height/3.5];
    [self addSubview:self.changLau];
    
    self.registerBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.changLau.width/2.5, self.height/12)];
    self.registerBtn.center = CGPointMake(self.changLau.x+self.registerBtn.width/2, self.changLau.frame.origin.y-self.registerBtn.height);
    self.registerBtn.backgroundColor = [UIColor clearColor];
    [self.registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [self.registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.registerBtn.layer.masksToBounds = YES;
    self.registerBtn.layer.cornerRadius = 8;
    self.registerBtn.layer.borderWidth = 2;
    self.registerBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.registerBtn.titleLabel.font=[UIFont fontWithName:kFontName size:self.registerBtn.height/3.5];
    [self addSubview:self.registerBtn];
    
    
    
    self.loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,  self.registerBtn.width, self.height/12)];
    self.loginBtn.center = CGPointMake(self.changLau.x+self.changLau.width-self.loginBtn.width/2, self.changLau.frame.origin.y-self.loginBtn.height);
    self.loginBtn.backgroundColor = [UIColor clearColor];
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [self.loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loginBtn.layer.masksToBounds = YES;
    self.loginBtn.layer.cornerRadius = 8;
    self.loginBtn.layer.borderWidth = 2;
    self.loginBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.loginBtn.titleLabel.font=[UIFont fontWithName:kFontName size:self.loginBtn.height/3.5];
    [self addSubview:self.loginBtn];
    
   
    
}

@end
